package com.iterator.controller.web.marketManager;

import com.iterator.bean.web.lc.OrderBean.OrderDetailVO;
import com.iterator.bean.web.lc.OrderBean.OrderListBO;
import com.iterator.bean.web.lc.OrderBean.OrderListVO;
import com.iterator.bean.web.lc.OrderBean.OrderRefundBO;
import com.iterator.bean.web.lc.OrderBean.OrderShipBO;
import com.iterator.bean.web.pojo.BaseRespVo;
import com.iterator.service.web.marketManager.OrderServiceImpl;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RequestMapping("admin/order")
@RestController
public class OrderController {

    @Autowired
    OrderServiceImpl orderService;
    @RequestMapping("list")
    @RequiresPermissions("admin:order:list")
    public BaseRespVo list(@Valid OrderListBO listBO, BindingResult result){
        if(result.hasFieldErrors()){
            return BaseRespVo.fail("参数错误");
        }
        OrderListVO orderListVO = orderService.getList(listBO);
        return BaseRespVo.ok(orderListVO);
    }

    @RequestMapping("detail")
    @RequiresPermissions("admin:order:read")
    public BaseRespVo detail(Integer id){
        OrderDetailVO orderDetailVO = orderService.getDetail(id);
        return BaseRespVo.ok(orderDetailVO);
    }
    @RequestMapping("refund")
    @RequiresPermissions("admin:order:refund")
    public BaseRespVo refund(@RequestBody OrderRefundBO refundBO){

        Integer update = orderService.refund(refundBO);
        return BaseRespVo.ok();
    }

    @RequestMapping("ship")
    @RequiresPermissions("admin:order:ship")
    public BaseRespVo ship(@RequestBody @Valid OrderShipBO shipBO){
        orderService.ship(shipBO);
        return BaseRespVo.ok();
    }

    /**
     * 评论回复,dhy
     *
     * @return 回复固定内容
     */
    @RequestMapping("reply")
    public BaseRespVo reply(@RequestBody String content){
        return BaseRespVo.fail("此功能臣妾实在做不到");
    }


}
